###Replication File for Big Lie and Misperceptions--Journal of Experimental Political Science (Pilot Analyses)###
###James J. Fahey###
library(dplyr)
library(foreign) #for importing data
library(rio) #for importing data
library(logr)

#Adjust Code to Open Relevant Data
###Set working directory to wherever replication file is stored###

Pilot <- import("Pilot_Conspiracy_Data.csv")

####Variable recoding (Pilot 1)####
#Recode variables into dummies such that 1 = endorses conspiracy theory, 0 == endorses alternative explanation or does not know
Pilot <- Pilot %>%
  mutate(Flu_Recode = case_when (
    Pilot$Flu == 1 ~1,
    Pilot$Flu == 2 ~0,
    Pilot$Flu == 3 ~0))

Pilot <- Pilot %>%
  mutate(Moon_Recode = case_when (
    Pilot$MoonLanding == 1 ~1,
    Pilot$MoonLanding == 2 ~0,
    Pilot$MoonLanding == 3 ~0))

Pilot <- Pilot %>%
  mutate(Bush_911_Recode = case_when (
    Pilot$BushDid911 == 1 ~1,
    Pilot$BushDid911 == 2 ~0,
    Pilot$BushDid911== 3 ~0))

Pilot <- Pilot %>%
  mutate(Area51_Recode = case_when (
    Pilot$Area51 == 1 ~1,
    Pilot$Area51 == 2 ~0,
    Pilot$Area51== 3 ~0))

Pilot <- Pilot %>%
  mutate(Flouride_Recode = case_when (
    Pilot$Flouride == 1 ~1,
    Pilot$Flouride == 2 ~0,
    Pilot$Flouride== 3 ~0))

Pilot <- Pilot %>%
  mutate(Epstein_Recode = case_when (
    Pilot$Epstein == 1 ~1,
    Pilot$Epstein == 2 ~0,
    Pilot$Epstein== 3 ~0))

Pilot <- Pilot %>%
  mutate(Iraq_Recode = case_when (
    Pilot$Iraq == 1 ~1,
    Pilot$Iraq == 2 ~0,
    Pilot$Iraq== 3 ~0))

Pilot <- Pilot %>%
  mutate(Chemtrails_Recode = case_when (
    Pilot$Chemtrails == 1 ~1,
    Pilot$Chemtrails == 2 ~0,
    Pilot$Chemtrails== 3 ~0))

Pilot <- Pilot %>%
  mutate(Katrina_Recode = case_when (
    Pilot$Katrina == 1 ~1,
    Pilot$Katrina == 2 ~0,
    Pilot$Katrina== 3 ~0))

Pilot <- Pilot %>%
  mutate(Election_Recode = case_when (
    Pilot$ElectionWinner == 1 ~1,
    Pilot$ElectionWinner == 2 ~0,
    Pilot$ElectionWinner== 3 ~0))

Pilot <- Pilot %>%
  mutate(Antifa_Recode = case_when (
    Pilot$Antifa == 1 ~1,
    Pilot$Antifa == 2 ~0,
    Pilot$Antifa == 3 ~0))

Pilot <- Pilot %>%
  mutate(VotesChanged_Recode = case_when (
    Pilot$VotesChanged == 1 ~1,
    Pilot$VotesChanged == 2 ~0,
    Pilot$VotesChanged == 3 ~0))

Pilot <- Pilot %>%
  mutate(FlatEarth_Recode = case_when (
    Pilot$FlatEarth == 1 ~1,
    Pilot$FlatEarth == 2 ~0,
    Pilot$FlatEarth == 3 ~0))

####Overall Means of Conspiracy Theories (Found in Appendices A.1.1 & A.1.2)####

by_PID <- Pilot %>% group_by(PID)

by_PID %>% summarise(
  Area51 = mean(Area51_Recode, na.rm = TRUE),
  Bush911 = mean(Bush_911_Recode, na.rm = TRUE),
  FlatEarth = mean(FlatEarth_Recode, na.rm = TRUE),
  VotesChanged = mean(VotesChanged_Recode, na.rm = TRUE),
  Antifa = mean(Antifa_Recode, na.rm = TRUE),
  Election= mean(Election_Recode, na.rm = TRUE),
  Katrina = mean(Katrina_Recode, na.rm = TRUE),
  Epstein = mean (Epstein_Recode, na.rm = TRUE),
  Iraq = mean(Iraq_Recode, na.rm = TRUE),
  Chemtrails = mean (Chemtrails_Recode, na.rm = TRUE),
  Flouride = mean (Flouride_Recode, na.rm = TRUE),
  Moonlanding = mean(Moon_Recode, na.rm = TRUE),
  Flu = mean (Flu_Recode, na.rm = TRUE),
)


####Pilot Data Two Analysis####

Pilot_2 <- import("Pilot_Conspiracy_2_Data.csv")

#Recode variables into dummies such that 1 = endorses conspiracy theory, 0 == endorses alternative explanation or does not know

Pilot_2 <- Pilot_2 %>%
  mutate(Flu_Recode = case_when (
    Pilot_2$Flu == 1 ~1,
    Pilot_2$Flu == 2 ~0,
    Pilot_2$Flu == 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Moon_Recode = case_when (
    Pilot_2$MoonLanding == 1 ~1,
    Pilot_2$MoonLanding == 2 ~0,
    Pilot_2$MoonLanding == 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Bush_911_Recode = case_when (
    Pilot_2$BushDid911 == 1 ~1,
    Pilot_2$BushDid911 == 2 ~0,
    Pilot_2$BushDid911== 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Covid19_Recode = case_when (
    Pilot_2$COVID19_Conspiracy == 1 ~1,
    Pilot_2$COVID19_Conspiracy == 2 ~0,
    Pilot_2$COVID19_Conspiracy== 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Flouride_Recode = case_when (
    Pilot_2$Flouride == 1 ~1,
    Pilot_2$Flouride == 2 ~0,
    Pilot_2$Flouride== 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Epstein_Recode = case_when (
    Pilot_2$Epstein == 1 ~1,
    Pilot_2$Epstein == 2 ~0,
    Pilot_2$Epstein== 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Immigrant_Recode = case_when (
    Pilot_2$Immigrant_Voted == 1 ~1,
    Pilot_2$Immigrant_Voted == 2 ~0,
    Pilot_2$Immigrant_Voted== 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Election_Recode = case_when (
    Pilot_2$ElectionWinner == 1 ~1,
    Pilot_2$ElectionWinner == 2 ~0,
    Pilot_2$ElectionWinner== 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(Antifa_Recode = case_when (
    Pilot_2$Antifa == 1 ~1,
    Pilot_2$Antifa == 2 ~0,
    Pilot_2$Antifa == 3 ~0))

Pilot_2 <- Pilot_2 %>%
  mutate(VotesChanged_Recode = case_when (
    Pilot_2$VotesChanged == 1 ~1,
    Pilot_2$VotesChanged == 2 ~0,
    Pilot_2$VotesChanged == 3 ~0))

#PID--Including Leaners 
Pilot_2 <- Pilot_2 %>%
  mutate(PID_Leaners = case_when (
    Pilot_2$PID == 1~1, 
    Pilot_2$PID == 2 ~ 2, 
    Pilot_2$ind1 == 1 ~2,
    Pilot_2$ind1 == 2 ~1, 
    Pilot_2$ind1 == 3 ~ 3
  ))

####Overall Means of Conspiracy Theories (Found in Appendices A.2.1 & A.2.2)####

by_PID_2 <- Pilot_2 %>% group_by(PID_Leaners)

by_PID_2 %>% summarise(
  Bush911 = mean(Bush_911_Recode, na.rm = TRUE),
  ImmigrantVote = mean(Immigrant_Recode, na.rm = TRUE),
  VotesChanged = mean(VotesChanged_Recode, na.rm = TRUE),
  Antifa = mean(Antifa_Recode, na.rm = TRUE),
  Election= mean(Election_Recode, na.rm = TRUE),
  Covid = mean(Covid19_Recode, na.rm = TRUE),
  Epstein = mean (Epstein_Recode, na.rm = TRUE),
  Flouride = mean (Flouride_Recode, na.rm = TRUE),
  Moonlanding = mean(Moon_Recode, na.rm = TRUE),
  Flu = mean (Flu_Recode, na.rm = TRUE),
)




